package com.tf_cut.backend.agent.statistics.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.tf_cut.backend.agent.statistics.vo.AgentCommissionVo;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.mapper.AgentCommissionMapper;

@Service
@Transactional
public class AgentCommissionServiceImpl implements AgentCommissionService {

    @PersistenceContext
    private EntityManager em;
    
    @Autowired
    private AgentCommissionMapper agentCommissionMapper;
    
    @Override
    public PageInfo<AgentCommissionVo> findAlreadyCommission(AgentCommissionVo vo){
    	PageHelper.startPage(vo.getPage() , vo.getRows());
    	List<AgentCommissionVo> listVo = agentCommissionMapper.findAlreadyCommission(vo);
		com.github.pagehelper.PageInfo<AgentCommissionVo> pageinfo = new com.github.pagehelper.PageInfo<>(listVo);
		
		PageInfo<AgentCommissionVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageinfo.getPageNum());//页码
		returnPageInfo.setPageSize(pageinfo.getPageSize());//页面大小
		returnPageInfo.setRows(pageinfo.getList());//分页结果
		returnPageInfo.setRecords((int)pageinfo.getTotal());//总记录数
		returnPageInfo.setTotal(pageinfo.getPages());//总页数
		return returnPageInfo;
    }

	@Override
	public AgentCommissionVo findCommissionWithAgent(AgentCommissionVo vo) {
		return agentCommissionMapper.findCommissionWithAgent(vo);
	}

	@Override
	public List<AgentCommissionVo> findCommission(AgentCommissionVo vo) {
		return agentCommissionMapper.findCommission(vo);
	}
}
